<?php include('header.php'); ?>
<script type="text/javascript">
$(document).ready(function() {
	$('#country_id').change(function(){
		populate_zone_menu();
	});	

});
// context is ship or bill
function populate_zone_menu(value)
{
	$.post('<?php echo site_url('locations/get_zone_menu');?>',{id:$('#country_id').val()}, function(data) {
		$('#zone_id').html(data);
	});
}
</script>

<?php echo form_open_multipart($this->config->item('admin_folder').'/restaurants/form/'.$id); ?>

<div class="tabbable">

	<ul class="nav nav-tabs">
		<li class="active"><a href="#description_tab" data-toggle="tab"><?php echo lang('description');?></a></li>
		<!--li><a href="#attributes_tab" data-toggle="tab"><?php echo lang('attributes');?></a></li>
		<li><a href="#seo_tab" data-toggle="tab"><?php echo lang('seo');?></a></li-->
	</ul>

	<div class="tab-content">
		<div class="tab-pane active" id="description_tab">
			
			<fieldset>
				<?php
				$address_form_prefix = 'bill';
				
				
				$countries = $this->Location_model->get_countries_menu();
				if ($id != null){
					$coun = $this->Location_model->get_zone_arean($id);
				
					$dodo = $coun->zone_id;
					$kuah = $coun->country_id;
				}

				if(!empty($customer[$address_form_prefix.'_address']['country_id']))
				{
					$zone_menu	= $this->Location_model->get_zones_menu($customer[$address_form_prefix.'_address']['country_id']);
				}
				else
				{
					if ($id != null){
						$zone_menu = array(''=>'')+$this->Location_model->get_zones_menu($kuah);
					} else {
						$zone_menu = array(''=>'')+$this->Location_model->get_zones_menu(array_shift(array_keys($countries)));
					}
				}
				
				?>
				<div class="row">
					<div class="span3">
						<label ><?php echo lang('address_country');?><b class="r"> *</b></label>
						<?php 
						if ($id == null){
							echo form_dropdown('country_id',$countries, @$customer[$address_form_prefix.'_address']['country_id'], 'id="country_id" class="address span3"');
							//echo $kuah;
						}else if ($kuah != 0) {
							echo form_dropdown('country_id',$countries, $kuah);
							//echo $kuah;
						} ?>
					</div>
					<div class="span3">
						<label ><?php echo lang('address_state');?><b class="r"> *</b></label>
						
						<?php 
						
						if($id == null){
							echo form_dropdown('zone_id',$zone_menu, @$customer[$address_form_prefix.'_address']['zone_id'], 'id="zone_id" class="address span3"');
							//echo $dodo;
						}else if ($dodo != 0) {
							echo form_dropdown('zone_id',$zone_menu, $dodo);
							//echo $dodo;
						}  ?>
					</div>
				</div>
			
				<label for="name"><?php echo lang('name');?></label>
				<?php
				$data	= array('name'=>'name', 'value'=>set_value('name', $name), 'class'=>'span12');
				echo form_input($data);
				?>
				
				<label for="alamat"><?php echo 'Alamat';?></label>
				<?php
				$data	= array('name'=>'alamat', 'value'=>set_value('alamat', $alamat), 'class'=>'span12');
				echo form_input($data);
				?>
				
				<label for="description"><?php echo lang('description');?></label>
				<?php
				$data	= array('name'=>'description', 'class'=>'redactor', 'value'=>set_value('description', $description));
				echo form_textarea($data);
				?>
				
				<br>
				<?php
					$jbh = array();
					$jbm = array();
					$jth = array();
					$jtm = array();
					for ($i = 0; $i <= 23; $i++)
					$jbh[$i] = $i;
					echo 'Jam Buka: ';
					echo form_dropdown('jam_buka_hour',$jbh, substr($jam_buka,0,2));
					for ($m = 0; $m <= 59; $m++)
					if(strlen($m) == 1)
					{$m = "0".$m;
					$jbm[$m] = $m;
					} else
					{$jbm[$m] = $m;}
					echo ' : ';
					echo form_dropdown('jam_buka_minute',$jbm, substr($jam_buka,3,2));
					echo '<br>';
					for ($j = 0; $j <= 23; $j++)
					$jth[$j] = $j;
					echo 'Jam Tutup: ';
					echo form_dropdown('jam_tutup_hour',$jth, substr($jam_tutup,0,2));
					for ($h = 0; $h <= 59; $h++)
					if(strlen($h) == 1)
					{$h = "0".$h;
					$jtm[$h] = $h;
					} else
					{$jtm[$h] = $h;}
					echo ' : ';
					echo form_dropdown('jam_tutup_minute',$jtm, substr($jam_tutup,3,2));
				?>
				
				<br></br>
				
				<label for="image"><?php echo lang('image');?> </label>
				<div class="input-append">
					<?php echo form_upload(array('name'=>'image'));?><span class="add-on"><?php echo lang('max_file_size');?> <?php echo  $this->config->item('size_limit')/1024; ?>kb</span>
				</div>
					
				<?php if($id && $image != ''):?>
				
				<div style="text-align:center; padding:5px; border:1px solid #ddd;"><img src="<?php echo base_url('uploads/images/small/'.$image);?>" alt="current"/><br/><?php echo lang('current_file');?></div>
				
				<?php endif;?>
				
				<label for="seo_title"><?php echo lang('seo_title');?> </label>
				<?php
				$data	= array('name'=>'seo_title', 'value'=>set_value('seo_title', $seo_title), 'class'=>'span12');
				echo form_input($data);
				?>
				
				<label><?php echo lang('meta');?></label> 
				<?php
				$data	= array('rows'=>3, 'name'=>'meta', 'value'=>set_value('meta', html_entity_decode($meta)), 'class'=>'span12');
				echo form_textarea($data);
				?>
				<p class="help-block"><?php echo lang('meta_data_description');?></p>
			</fieldset>
		</div>

		<!--div class="tab-pane" id="attributes_tab">
			
			<fieldset>
				<label for="slug"><?php echo lang('slug');?> </label>
				<?php
				$data	= array('name'=>'slug', 'value'=>set_value('slug', $slug));
				echo form_input($data);
				?>
				
				<label for="sequence"><?php echo lang('sequence');?> </label>
				<?php
				$data	= array('name'=>'sequence', 'value'=>set_value('sequence', $sequence));
				echo form_input($data);
				?>
				
				<label for="slug"><?php echo lang('parent');?> </label>
				<?php
				$data	= array(0 => 'Top Level Category');
				foreach($restaurants as $parent)
				{
					if($parent->id != $id)
					{
						$data[$parent->id] = $parent->name;
					}
				}
				echo form_dropdown('parent_id', $data, $parent_id);
				?>
				
				<label for="excerpt"><?php echo lang('excerpt');?> </label>
				<?php
				$data	= array('name'=>'excerpt', 'value'=>set_value('excerpt', $excerpt), 'class'=>'span12', 'rows'=>3);
				echo form_textarea($data);
				?>
				
			</fieldset>
			
		</div-->
		
		<!--div class="tab-pane" id="seo_tab">
			<fieldset>
				
			</fieldset>
		</div-->
	</div>

</div>

<div class="form-actions">
	<button type="submit" class="btn btn-primary"><?php echo lang('form_save');?></button>
</div>
</form>

<script type="text/javascript">
$('form').submit(function() {
	$('.btn').attr('disabled', true).addClass('disabled');
});
</script>
<?php include('footer.php');